package pchi.pchicamera.functions;

import java.io.OutputStream;

import pchi.pchicamera.helpers.ExternalStorageHelpers;
import android.content.ContentValues;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.net.Uri;
import android.provider.MediaStore.Images.Media;
import android.util.Log;
import android.widget.Toast;

public class OnTouchImage {

	public static Uri saveImage(Context context, Bitmap img) {

		if (!ExternalStorageHelpers.externalStorageAvailable())
			return null;
		if (img == null)
			return null;
		Uri imageFileUri = context.getContentResolver().insert(
				Media.EXTERNAL_CONTENT_URI, new ContentValues());
		try {
			OutputStream imageFileOS = context.getContentResolver()
					.openOutputStream(imageFileUri);
			img.compress(CompressFormat.JPEG, 90, imageFileOS);
			Toast.makeText(context, "Saved!", Toast.LENGTH_SHORT).show();
		} catch (Exception e) {
			Log.v("SAVE IMAGE", e.getMessage());
		}
		return imageFileUri;
	}

}
